const express = require("express");
const router = express.Router();
const mqttClient = require('../utils/mqttClient');

//根据设备id开门
router.get('/open-door/:doorId', async (req, res) => {
    const doorId = req.params.doorId;
    if (!doorId) {
        return res.status(400).cc('门ID不能为空');
    }

    const { username } = req.auth;
    try {
        const status = await mqttClient.openDoor(doorId, username);
        res.cc(`开门${status}`, true);
    } catch (error) {
        res.cc(error.message);
    }
});


module.exports = router;